<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/templateListar.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

	<ui:define name="conteudo">
		<ui:param name="actionBean" value="#{funcionarioMB}" />

		<h:form id="frmFuncionario">

			<p:hotkey bind="esc"
				handler="document.getElementById('frmTab:btnCancelar').click()" />

		</h:form>
		<h:form id="frmTab">
			<h:panelGrid columns="2">
				<p:outputLabel value="Função/Cargo:" for="cargo" />
				<p:selectOneMenu id="cargo" filterMatchMode="contains" filter="true"
					value="#{funcionarioMB.cargo}" style="width:250px;"
					converter="cargoConverter">
					<f:selectItem itemLabel="" itemValue="#{null}"></f:selectItem>
					<f:selectItems value="#{funcionarioMB.listaCargo}" var="cargo"
						itemLabel="#{cargo.descricao}" itemValue="#{cargo}"></f:selectItems>
					<p:ajax event="change" listener="#{funcionarioMB.buscar}"
						update="tabela"></p:ajax>
				</p:selectOneMenu>
			</h:panelGrid>
			<p:commandButton id="btnCancelar" action="#{funcionarioMB.sair}"
				style="display:none" immediate="true" value="sair"></p:commandButton>
			<p:commandButton action="#{funcionarioMB.prepararIncluir}"
				value="Novo Registro" icon="ui-icon-disk" style="float:left">

			</p:commandButton>
			<p:dataTable id="tabela" var="item" value="#{funcionarioMB.lista}"
				widgetVar="tbfunc" paginator="true" rows="10"
				emptyMessage="Não há registros na lista" paginatorPosition="bottom"
				rowKey="#{item.matricula}"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				currentPageReportTemplate="(Página: {currentPage}/{totalPages})"
				rowsPerPageTemplate="10,15,25,50,100" selectionMode="single">
				<f:facet name="header">Cadastro de Funcionários
					
				</f:facet>
				<p:column headerText="Matricula" style="width: 10%;"
					sortBy="#{item.matricula}">
					<h:outputText value="#{item.matricula}" />
				</p:column>
				<p:column headerText="Nome" sortBy="#{item.dadosCadastro.nome}"
					filterBy="#{item.dadosCadastro.nome}" filterMatchMode="contains">
					<h:outputText value="#{item.dadosCadastro.nome}" />
				</p:column>

				<p:column headerText="CPF" sortBy="#{item.dadosCadastro.cnpjCpf}"
					filterBy="#{item.dadosCadastro.cnpjCpf}" filterMatchMode="exact">
					<h:outputText value="#{item.dadosCadastro.cnpjCpf}" />
				</p:column>

				<p:column headerText="E-mail" sortBy="#{item.email}"
					filterMatchMode="contains" filterBy="#{item.dadosCadastro.email}">
					<h:outputText value="#{item.dadosCadastro.email}" />
				</p:column>


				<p:column headerText="Cargo" sortBy="#{item.cargo.descricao}">
					<h:outputText value="#{item.cargo.descricao}" />
				</p:column>


				<p:column headerText="Ação" style="text-align:center">

					<p:commandButton action="#{funcionarioMB.prepararAlterar}"
						styleClass="styleBotao" title="Alterar" icon="ui-icon-pencil">

						<f:setPropertyActionListener value="#{item}"
							target="#{funcionarioMB.funcionario}" />
					</p:commandButton>

					<p:commandButton action="#{funcionarioMB.prepararConsultar}"
						styleClass="styleBotao" title="Consultar" icon="ui-icon-search">
						<f:setPropertyActionListener value="#{item}"
							target="#{funcionarioMB.funcionario}" />
					</p:commandButton>

					<p:commandButton actionListener="#{funcionarioMB.excluir}"
						title="Excluir" icon="ui-icon-close" styleClass="styleRed"
						update=":Excluir" oncomplete="confirmation.show()">

						<f:setPropertyActionListener value="#{item}"
							target="#{funcionarioMB.funcionario}" />
					</p:commandButton>

				</p:column>


				<f:facet name="footer">
					<p:outputLabel value="Total de " />
					<p:outputLabel
						value="#{fn:length(funcionarioMB.lista)} registro(s)" />

				</f:facet>
			</p:dataTable>
		</h:form>

		<ui:include src="/includes/confirmacaoExcluir.xhtml" />
	</ui:define>
</ui:composition>
